{extend name="$BASE_LIST" /}
{block name="body"}
<style type="text/css">
.frm_input_box{width: 225px!important}
</style>
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">锁仓列表</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名\手机号" value="" class="frm_input" />
        </span>
        <span class="right">
             <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i>添加锁仓</button>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:150,align:'center'">用户名</th>
        <th data-options="field:'phone',width:150,align:'center'">手机号</th>
        <th data-options="field:'amount',width:150,align:'center'">总额度</th>
        <th data-options="field:'release_tax',width:150,align:'center'">释放比率（%）</th>
        <th data-options="field:'remaining_amount',width:150,align:'center'">剩余额度</th>
        <th data-options="field:'type',width:150,align:'center',formatter:formatType">锁仓类型</th>
        </thead>
        <thead>
            <tr>
                 <th data-options="field:'status',width:80,align:'center',formatter:formatStatus">是否结束</th>
                 <th data-options="field:'balance_type',width:80,align:'center',formatter:formatBalanceType">币种</th>
                <th data-options="field:'create_time',width:160,align:'center'">添加时间</th>
                 <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript">

    //状态
    function formatStatus(value,row,index){
        switch (value){
            case 0 :
                var text = '<span style="color:green">进行中</span>';
                break;
            default:
                var text = '<span style="color:red">已结束</span>';
        }
        return text;
    }

    //锁仓类型
    function formatType(value,row,index){
        switch (value){
            case 2 :
                var text = '<span style="color:#000fef;font-weight:900">代理锁仓</span>';
                break;
            case 3 :
                var text = '<span style="color:#e806c3;font-weight:900">希望锁仓</span>';
                break;
            default:
                var text = '<span style="color:#020100;font-weight:900">普通锁仓</span>';
        }
        return text;
    }

    //币种
    function formatBalanceType(value,row,index){
        switch (value){
            case 1 :
                var text = '<span style="color:green">USDT</span>';
                break;
            case 2 :
                var text = '<span style="color:#071e80">DC</span>';
                break;
            default:
                var text = '<span style="color:red">KOF</span>';
        }
        return text;
    }

    function formatImg(value) {
        html = '';
        if(value!=null){
            html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
        }
        return html;
        
    }
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
            html += '<button type="button" onclick="editor(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        if(row['status'] == 0){
            html += '<button type="button" onclick="isEnd(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>结束</button>';
        }
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>删除</button>';
        html += '</span>';
        return html;
    }

    //解冻账号
    function isEnd(id) {
        confirm("确认要结束此锁仓吗？", function () {
            var url = getURL('isEnd');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

    function editor(id) {
        var url = getURL('editor', 'id=' + id);
        openBarWin('编辑', 600, 200, url, function () {
            reload();
        }, ['保存', '取消']);
    }

    function del(id) {
        confirm("确认要删除吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('edit');
        openBarWin('添加', 830, 300, url, function () {
            reload();
        });
    });
     $("#add_days").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_days');
        openBarWin('补偿天数', 400, 300, url, function () {
            reload();
        }, ['保存', '取消']);
    });

    $("#js_search").click(function () {
        reload();
    });
    function reload()
    {
        var type = $("#type").val();
        var keyword = $("#js_keyword").val();
        var is_hot = $("#is_hot").val();
        var is_headlines = $("#is_headlines").val();
        var is_public = $("#is_public").val();
        var is_allow = $("#is_allow").val();
        var is_top = $("#is_top").val();
        $('#grid-table').datagrid('reload', {keyword: keyword});
    }
</script>
{/block}